package com.fy.controller;

import com.fy.pojo.User;
import com.fy.service.UserService;
import javafx.scene.control.Alert;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.UUID;

@Controller
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping("Reg")
    public String toReg(User user){
        String salt= UUID.randomUUID().toString();
        DigestUtils.md5Digest((user.getPassword()+salt).getBytes());
        int i = userService.insert(user);
        return "redirect:tologin";
    }
    @RequestMapping("toReg")
    public String toReg(){
        return "Reg";
    }
    @RequestMapping("tologin")
    public String tologin(){
        return "login";
    }

    @RequestMapping("login")
    public String login(String username){
        User user = userService.select(username);
        if(user.getUsername().equals(username)){
            return "redirect:success";
        }
        return "login";
    }


}
